<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="140px">
        <el-row>
            <el-col :span="6">
            <el-form-item label="医院名称">
              <template>
                <el-select v-model="form.hospitalId" clearable filterable placeholder="请选择">
                  <el-option
                    v-for="item in hospitalOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院类型">
              <el-select v-model="form.tagsId" clearable placeholder="请选择">
                <el-option
                  v-for="item in tagOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属分公司">
              <el-select v-model="form.officeId" clearable placeholder="请选择">
                <el-option
                  v-for="item in officeOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="App上架状态">
              <el-select v-model="form.status" clearable placeholder="请选择">
                <el-option
                  v-for="item in statusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="严选状态">
              <el-select v-model="form.examStatus" clearable placeholder="请选择">
                <el-option
                  v-for="item in examStatusOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              v-if="hasPermission('AdminExamQuesProvider.exportHospitalExamList')"
              plain                       
              type="primary"
              class="el-icon-download"
              @click="excelEvent"
            >导出</el-button>
            <!-- <el-button
              plain                       
              type="primary"
              class="el-icon-download"
              @click="excelEvent"
            >导出</el-button> -->
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column type="index" label="编号" width="100px"></el-table-column>
        <el-table-column prop="hospitalName" label="医院名称"></el-table-column>
        <el-table-column prop="tagsName" label="医院类型"></el-table-column>
        <el-table-column prop="branchOfficeName" label="所属分公司"></el-table-column>
        <el-table-column prop="statusStr" label="App上架状态"></el-table-column>
        <el-table-column prop="examStatusStr" label="245严选状态"></el-table-column>
        <el-table-column prop="examScore" label="严选得分" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.examScore}}</span>
            <span v-if="scope.row.examStatus==0">--</span>
          </template>
        </el-table-column>
        <el-table-column prop="updatedAt" label="提交时间"></el-table-column>
        <el-table-column fixed="right" label="操作" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.examStatus==1">
            <el-button
              type="text"
              size="small"
              @click="toRoutes('StrictSelectionInfo',scope.row.hospitalId,1)"
            >查看</el-button>
            <el-button
              type="text"
              size="small"
              @click="toRoutes('StrictSelectionInfo',scope.row.hospitalId,2)"
            >编辑</el-button>
            </span>
            <el-button
              v-if="scope.row.examStatus==0"
              type="text"
              size="small"
              @click="toRoutes('StrictSelectionInfo',scope.row.hospitalId,3)"
            >添加严选结果</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { hospitalExamList, handleExport } from "@/api/StrictSelection";
import { hospitalList } from "@/api/financialBack";
import { findHospitalTagsList } from "@/api/hospitalLabel";
import { companyList } from "@/api/branchOfficeDropDown";
import { downFile } from "@/filters/index";
import { exportfile } from "@/api/exporfile";
export default {
    name:"StrictSelection",
  data() {
    return {
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      tableLoading: false,
      // 0-已上架 1-未上架
      statusOption: [
        {
          value: null,
          label: "全部"
        },
        {
          value: 1,
          label: "未上架"
        },
        {
          value: 0,
          label: "已上架"
        }
      ],
      // 0-未严选 1-严选通过
      examStatusOption: [
        {
          value: null,
          label: "全部"
        },
        {
          value: 1,
          label: "严选通过"
        },
        {
          value: 0,
          label: "未严选"
        }
      ],
      hospitalOptions: [],
      tagOption:[],
      officeOption:[],
      form: {
        hospitalId: null,
        tagsId:null,
        officeId:null,
        status:null,
        examStatus:null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 0,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(e);
    },
    status: function(val) {
      return this.statusOption.map(item => {
        if (item.value == val) {
          return item.label;
        }
      });
    }
  },
  watch:{
    "form.tagsId"(val){
      if(val=""){
        this.form.tagsId=null
      }
    }
  },
  created() {
    this.getHospital();
    this.getCompanyList();
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    //按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    //成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    //失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    //医院名称
    getHospital() {
      hospitalList().then(res => {
        //  console.log(res.data.data)
        if (res.data.data) {
          this.hospitalOptions = res.data.data.map(item => {
            return { value: item.id + "", label: item.name };
          });
        }
      });
    },
    // 获取分公司列表
        getCompanyList() {
            companyList()
                .then(res => {
                    const resData = res.data.data;
                    const newData = [];
                    resData.forEach(e => {
                        newData.push({
                            value: e.id,
                            label: e.name
                        });
                    });
                    this.officeOption = newData;
                    this.officeOption.unshift({
                        value: null,
                        label: "全部"
                    });
                    this.offLoad = false
                })
                .catch(error => {
                    this.offLoad = false
                    this.$message.error(error);
                });
            // 医院类型
            const datas = {
                pageNum: 0,
                pageSize: 2000
            };
            findHospitalTagsList(datas).then(res => {
                const resData = res.data.data.list;
                const newData = [];
                resData.forEach(e => {
                    newData.push({
                        value: e.id,
                        label: e.name
                    });
                });
                this.tagOption = newData;
                this.tagOption.unshift({
                    value: null,
                    label: "全部"
                });
            });
        },
    //查询
    searchFn() {
      this.form.pageNum = 1;
      // if (!this.form.hospitalId) {
      //   this.form.hospitalId = null;
      // }
      // if (!this.form.status) {
      //   this.form.status = null;
      // }
      // if (!this.form.examStatus) {
      //   this.form.examStatus = null;
      // }
      // if (!this.form.tagsId) {
      //   this.form.tagsId = null;
      // }
      // console.log(this.form)
      this.getList(this.form);
    },
    // 路由跳转
    toRoutes(e, userId,type) {
      let route = { name: e, query: { userId: userId,type:type } };
      this.$router.push(route);
    },
    //导出
    excelEvent() {
      handleExport(this.form).then(res => {
        exportfile(res);
      });
    },
    //列表数据获取
    getList(e) {
      this.tableLoading = true;
      let datas = e;
      hospitalExamList(datas)
        .then(res => {
          console.log(res);
          if (res.data.code == 0) {
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },

    //改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>